<form action="{:url()}" method="post" class="form_single">
    <div class="box">
      <div class="box-body">
        <div class="row">
          <div class="col-md-6">
            <div class="form-group">
              <label>组名</label>
              <span>（部门组名称）</span>
              <input class="form-control" name="group_name" placeholder="请输入组名" type="text">
            </div>
          </div>
 
          <div class="col-md-6">
            <div class="form-group">
              <label>负责人</label>
              <span>（部门负责人）</span>
              <input class="form-control" name="principal" placeholder="请输入负责人" type="text">
            </div>
          </div>
          
          <div class="col-md-6">
            <div class="form-group">
              <label>所属公司</label>
              <span class="">（组所属公司）</span>
                <select name="company_id" class="form-control" id="company_list">
                  <option value=''>请选择公司</option>
                    {volist name='company_list' id='vo'}
                        <option value="{$vo['id']}" >{$vo['name']}</option>
                    {/volist}
                </select>
            </div>
          </div>

          <div class="col-md-6">
            <div class="form-group">
              <label>所属部门</label>
              <span class="">（组所属部门）</span>
                <select name="branch_id" class="form-control" id="branch_list">
                  <option value=''>请选择部门</option>
                    <!-- {volist name='branch_list' id='vo'}
                        <option value="{$vo['id']}" >{$vo['branch_name']}</option>
                    {/volist} -->
                </select>
            </div>
          </div>
           
          <div class="col-md-6">
            <div class="form-group">
              <label>排序</label>
              <span>（数值越大排在越前）</span>
              <input class="form-control" name="sort" placeholder="请输入数值" type="number" >
            </div>
          </div>

        </div>
      </div>
      <div class="box-footer">
        
        {include file="layout/edit_btn_group"/}
      </div>
    </div>
    <script type="text/javascript">
           $('#company_list').change(function(){
    var options=$(this).children("option:selected");
     // options.attr('selected','selected'); 
    var company_id=options.val();
    $('#branch_list option').remove();
    $('#group_list option').remove();
     $("#group_list").append("<option value=''>请选择组</option>");
     $("#branch_list").append("<option value=''>请选择部门</option>");
    $.post('/admin/branch/branchlist',{company_id:company_id},function(data){
      $(data.data).each(function(index,item){ 
          var option="<option value="+item.id+">"+item.branch_name+"</option>"
          $("#branch_list").append(option);  
            // console.log(item); 
        }); 
    });  
  })

  $('#branch_list').change(function(){
    var options=$(this).children("option:selected");
     options.attr('selected','selected'); 
    var branch_id=options.val();
    $('#group_list option').remove();
     $("#group_list").append("<option value=''>请选择组</option>");
    // alert(branch_id);
    $.post('/admin/group/grouplist',{branch_id:branch_id},function(data){
      $(data.data).each(function(index,item){ 
          var option="<option value="+item.id+">"+item.group_name+"</option>"
          $("#group_list").append(option);  
            console.log(item); 
        }); 
    });  
  })
    </script>
</form>
